import request, { type ListResponse, type ListQuery } from "@/utils/request";
import { type UserProfileType } from "../user/profile";

const BASE_URL = "/api/internal/PaymentInfo";

export const PaymentAPI = {
  getPaymentList: (params: ListQuery) => {
    return request.get<any, ListResponse<PaymentType>>(`${BASE_URL}/`, {
      params,
    });
  },
  getPaymentDetail: (id: number) => {
    return request.get<any, PaymentType>(`${BASE_URL}/${id}/`);
  },
};

export type PaymentListQuery = {} & ListQuery;

/**
 * @description 支付状态
 * @enum no_pay 未支付
 * @enum processing 支付中
 * @enum paid 已支付
 * @enum refunding 退款中
 * @enum part_refund 部分退款
 * @enum full_refund 全额退款
 * @enum canceled 已取消
 * @enum error 支付失败
 */
export type PaymentStatus =
  | "no_pay"
  | "processing"
  | "paid"
  | "refunding"
  | "part_refund"
  | "full_refund"
  | "canceled"
  | "error";

export type PaymentType = {
  id: number;
  user: UserProfileType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  out_trade_no: string;
  transaction_id: string;
  status: PaymentStatus;
  provider: "wxpay";
  amount_payable: string;
  amount: string;
  refund_amount: string;
  success_time: null;
  description: string;
  origin_key: null;
  origin_id: null;
  tenant_id: null;
};

export default PaymentAPI;
